package online.sixfish.common.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;

/**
 * AsyncExecutorConfig
 * @author sixFish
 * @date 2024/04/22
 */
@Configuration
@EnableAsync
public class AsyncExecutorConfig {
    @Bean("executor")
    public Executor executor(){
        ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("Executor-%d").build();

        return new ThreadPoolExecutor(3, 10, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingDeque<Runnable>(1024), factory, new ThreadPoolExecutor.AbortPolicy());
    }
}
